package com.rainfull.util;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class HttpUtil {

	public static String PostInfo(String strUrl, String strPostInfo)
	{
		String strRet = "";
		if (strUrl == null || strPostInfo == null)
		{
			//数据不合法
			return strRet;
		}		
		try
		{
			URL infoUrl = new URL(strUrl);  
		    //取得连接  
		    HttpURLConnection conn = (HttpURLConnection) infoUrl.openConnection();		    
		    conn.setDoInput(true);
		    conn.setDoOutput(true);
		    conn.setRequestMethod("POST");
		    conn.setInstanceFollowRedirects(true);
		    conn.setUseCaches(false);
		    conn.setRequestProperty("Content-type","Application/x-www-form-urlencoded");
		    conn.setFixedLengthStreamingMode(strPostInfo.length());
		    conn.setConnectTimeout(15000);		    
		    conn.setReadTimeout(15000);
		    conn.connect();
		    DataOutputStream out = new DataOutputStream(conn.getOutputStream());			    
		    out.writeBytes(strPostInfo);
	        out.flush();
	        out.close();
		    BufferedReader r = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		    strRet = r.readLine();
		    r.close();
		    conn.disconnect();
		}
		catch(Exception e)
		{
			String ccc = e.getMessage();
			e.printStackTrace();
		}
	    return strRet;
	}
}